import { IPSAppDataEntity } from '../app/dataentity/ipsapp-data-entity';
import { IPSControl } from './ipscontrol';
import { IPSControlAction } from './ipscontrol-action';
import { IPSControlAttribute } from './ipscontrol-attribute';
import { IPSControlHandler } from './ipscontrol-handler';
import { IPSControlLogic } from './ipscontrol-logic';
import { IPSControlParam } from './ipscontrol-param';
import { IPSControlRender } from './ipscontrol-render';
import { IPSCtrlMsg } from '../res/ipsctrl-msg';
import { IPSSysCss } from '../res/ipssys-css';
import { IPSSysPFPlugin } from '../res/ipssys-pfplugin';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSControlImpl extends PSModelObjectImpl implements IPSControl {
  get codeName(): string {
    return this.M.codeName;
  }

  get controlStyle(): string {
    return this.M.controlStyle;
  }

  get controlType():
    | 'TOOLBAR'
    | 'GRID'
    | 'FORM'
    | 'SEARCHFORM'
    | 'DRBAR'
    | 'VIEWPANEL'
    | 'PICKUPVIEWPANEL'
    | 'DATAVIEW'
    | 'TREEGRID'
    | 'WFEXPBAR'
    | 'TREEVIEW'
    | 'TREEEXPBAR'
    | 'TABVIEWPANEL'
    | 'DRTAB'
    | 'CHART'
    | 'REPORTPANEL'
    | 'LIST'
    | 'MOBMDCTRL'
    | 'MULTIEDITVIEWPANEL'
    | 'WIZARDPANEL'
    | 'UPDATEPANEL'
    | 'SEARCHBAR'
    | 'DASHBOARD'
    | 'CALENDAR'
    | 'PANEL'
    | 'MAP'
    | 'GANTT'
    | 'TREEGRIDEX'
    | 'KANBAN'
    | 'CALENDAREXPBAR'
    | 'CHARTEXPBAR'
    | 'DATAVIEWEXPBAR'
    | 'GANTTEXPBAR'
    | 'GRIDEXPBAR'
    | 'LISTEXPBAR'
    | 'MAPEXPBAR'
    | 'STATEWIZARDPANEL'
    | 'APPMENU'
    | 'TABEXPPANEL'
    | 'CUSTOM' {
    return this.M.controlType;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get height(): number {
    return this.M.height != null ? this.M.height : 0.0;
  }

  protected hookeventnames: string[] | null = null;

  getHookEventNames(): string[] | null {
    if (this.hookeventnames == null) {
      const value = this.M.hookEventNames;
      if (value == null) {
        return null;
      }
      const arrayNode: any[] = value;
      if (arrayNode.length == 0) {
        return null;
      }
      const list: string[] = [];
      for (let i = 0; i < arrayNode.length; i++) {
        list.push(arrayNode[i]);
      }
      this.hookeventnames = list;
    }
    return this.hookeventnames.length == 0 ? null : this.hookeventnames;
  }

  get hookEventNames(): string[] | null {
    return this.getHookEventNames();
  }

  get logicName(): string {
    return this.M.logicName;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected psappdataentity: IPSAppDataEntity | null = null;

  getPSAppDataEntity(): IPSAppDataEntity | null {
    if (this.psappdataentity != null) return this.psappdataentity;
    const value = this.M.getPSAppDataEntity;
    if (value == null) {
      return null;
    }
    this.psappdataentity = this.getPSModel4('app.dataentity.IPSAppDataEntity', value, 'getPSAppDataEntity') as IPSAppDataEntity;
    return this.psappdataentity;
  }

  get psAppDataEntity(): IPSAppDataEntity | null {
    return this.getPSAppDataEntity();
  }

  getPSAppDataEntityMust(): IPSAppDataEntity {
    const value = this.getPSAppDataEntity();
    if (value == null) {
      throw new Error('未指定应用实体');
    }
    return value;
  }

  protected pscontrolattributes: IPSControlAttribute[] | null = null;

  getPSControlAttributes(): IPSControlAttribute[] | null {
    if (this.pscontrolattributes == null) {
      this.pscontrolattributes = this.fillChildListModel(this.M.getPSControlAttributes, 'control.IPSControlAttribute') as IPSControlAttribute[];
    }
    return this.pscontrolattributes;
  }

  get psControlAttributes(): IPSControlAttribute[] | null {
    return this.getPSControlAttributes();
  }

  findPSControlAttribute(objKey: any): IPSControlAttribute | null {
    return this.getPSModel5('control.IPSControlAttribute', this.getPSControlAttributes(), objKey) as IPSControlAttribute;
  }

  protected pscontrolhandler: IPSControlHandler | null = null;

  getPSControlHandler(): IPSControlHandler | null {
    if (this.pscontrolhandler != null) return this.pscontrolhandler;
    const value = this.M.getPSControlHandler;
    if (value == null) {
      return null;
    }
    this.pscontrolhandler = this.getPSModel4('control.IPSControlHandler', value, 'getPSControlHandler') as IPSControlHandler;
    return this.pscontrolhandler;
  }

  get psControlHandler(): IPSControlHandler | null {
    return this.getPSControlHandler();
  }

  getPSControlHandlerMust(): IPSControlHandler {
    const value = this.getPSControlHandler();
    if (value == null) {
      throw new Error('未指定部件处理');
    }
    return value;
  }

  protected pscontrollogics: IPSControlLogic[] | null = null;

  getPSControlLogics(): IPSControlLogic[] | null {
    if (this.pscontrollogics == null) {
      this.pscontrollogics = this.fillChildListModel(this.M.getPSControlLogics, 'control.IPSControlLogic') as IPSControlLogic[];
    }
    return this.pscontrollogics;
  }

  get psControlLogics(): IPSControlLogic[] | null {
    return this.getPSControlLogics();
  }

  findPSControlLogic(objKey: any): IPSControlLogic | null {
    return this.getPSModel5('control.IPSControlLogic', this.getPSControlLogics(), objKey) as IPSControlLogic;
  }

  protected pscontrolparam: IPSControlParam | null = null;

  getPSControlParam(): IPSControlParam | null {
    if (this.pscontrolparam != null) return this.pscontrolparam;
    const value = this.M.getPSControlParam;
    if (value == null) {
      return null;
    }
    this.pscontrolparam = this.getPSModel4('control.IPSControlParam', value, 'getPSControlParam') as IPSControlParam;
    return this.pscontrolparam;
  }

  get psControlParam(): IPSControlParam | null {
    return this.getPSControlParam();
  }

  getPSControlParamMust(): IPSControlParam {
    const value = this.getPSControlParam();
    if (value == null) {
      throw new Error('未指定部件参数');
    }
    return value;
  }

  protected pscontrolrenders: IPSControlRender[] | null = null;

  getPSControlRenders(): IPSControlRender[] | null {
    if (this.pscontrolrenders == null) {
      this.pscontrolrenders = this.fillChildListModel(this.M.getPSControlRenders, 'control.IPSControlRender') as IPSControlRender[];
    }
    return this.pscontrolrenders;
  }

  get psControlRenders(): IPSControlRender[] | null {
    return this.getPSControlRenders();
  }

  findPSControlRender(objKey: any): IPSControlRender | null {
    return this.getPSModel5('control.IPSControlRender', this.getPSControlRenders(), objKey) as IPSControlRender;
  }

  protected psctrlmsg: IPSCtrlMsg | null = null;

  getPSCtrlMsg(): IPSCtrlMsg | null {
    if (this.psctrlmsg != null) return this.psctrlmsg;
    const value = this.M.getPSCtrlMsg;
    if (value == null) {
      return null;
    }
    this.psctrlmsg = this.getPSModel4('res.IPSCtrlMsg', value, 'getPSCtrlMsg') as IPSCtrlMsg;
    return this.psctrlmsg;
  }

  get psCtrlMsg(): IPSCtrlMsg | null {
    return this.getPSCtrlMsg();
  }

  getPSCtrlMsgMust(): IPSCtrlMsg {
    const value = this.getPSCtrlMsg();
    if (value == null) {
      throw new Error('未指定部件消息');
    }
    return value;
  }

  protected pssyscss: IPSSysCss | null = null;

  getPSSysCss(): IPSSysCss | null {
    if (this.pssyscss != null) return this.pssyscss;
    const value = this.M.getPSSysCss;
    if (value == null) {
      return null;
    }
    this.pssyscss = this.getPSModel4('res.IPSSysCss', value, 'getPSSysCss') as IPSSysCss;
    return this.pssyscss;
  }

  get psSysCss(): IPSSysCss | null {
    return this.getPSSysCss();
  }

  getPSSysCssMust(): IPSSysCss {
    const value = this.getPSSysCss();
    if (value == null) {
      throw new Error('未指定界面样式');
    }
    return value;
  }

  protected pssyspfplugin: IPSSysPFPlugin | null = null;

  getPSSysPFPlugin(): IPSSysPFPlugin | null {
    if (this.pssyspfplugin != null) return this.pssyspfplugin;
    const value = this.M.getPSSysPFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyspfplugin = this.getPSModel4('res.IPSSysPFPlugin', value, 'getPSSysPFPlugin') as IPSSysPFPlugin;
    return this.pssyspfplugin;
  }

  get psSysPFPlugin(): IPSSysPFPlugin | null {
    return this.getPSSysPFPlugin();
  }

  getPSSysPFPluginMust(): IPSSysPFPlugin {
    const value = this.getPSSysPFPlugin();
    if (value == null) {
      throw new Error('未指定前端扩展插件');
    }
    return value;
  }

  protected user2pscontrolaction: IPSControlAction | null = null;

  getUser2PSControlAction(): IPSControlAction | null {
    if (this.user2pscontrolaction != null) return this.user2pscontrolaction;
    const value = this.M.getUser2PSControlAction;
    if (value == null) {
      return null;
    }
    this.user2pscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.user2pscontrolaction;
  }

  get user2PSControlAction(): IPSControlAction | null {
    return this.getUser2PSControlAction();
  }

  getUser2PSControlActionMust(): IPSControlAction {
    const value = this.getUser2PSControlAction();
    if (value == null) {
      throw new Error('未指定用户自定义行为2');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  protected userpscontrolaction: IPSControlAction | null = null;

  getUserPSControlAction(): IPSControlAction | null {
    if (this.userpscontrolaction != null) return this.userpscontrolaction;
    const value = this.M.getUserPSControlAction;
    if (value == null) {
      return null;
    }
    this.userpscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.userpscontrolaction;
  }

  get userPSControlAction(): IPSControlAction | null {
    return this.getUserPSControlAction();
  }

  getUserPSControlActionMust(): IPSControlAction {
    const value = this.getUserPSControlAction();
    if (value == null) {
      throw new Error('未指定用户自定义行为');
    }
    return value;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get width(): number {
    return this.M.width != null ? this.M.width : 0.0;
  }

  get cls(): string {
    return 'PSControlImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelObject' || cls == 'IPSObject' || cls == 'control.IPSControl') return true;
    return super.instanceof(cls);
  }
}
